package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MorePersonDataModel;
import com.rjwh.dingdong.client.mvp.presenter.IMorePersonDataPresenter;
import com.rjwh.dingdong.client.mvp.view.MorePersonDataView;
import com.rjwh.dingdong.client.util.ToastUtil;

/**
 * @author Kay
 * @ClassName MorePersonDataPresenter
 * @Description
 * @date 2016-8-5
 * @history 2016-8-5 author: description:
 */
public class MorePersonDataPresenter extends BasePresenter<MorePersonDataView> implements IMorePersonDataPresenter {

    private MorePersonDataModel model;

    public MorePersonDataPresenter(Context context, MorePersonDataView mMvpView) {
        super(context, mMvpView);
        model = new MorePersonDataModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (isViewAttached()) {
            getMvpView().dismissLoading();
            switch (businessType) {
                case NetConstant.SAVEPARENTDATA:
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS) {
                        getMvpView().updataData();
                        ToastUtil.showToast(getContext(), "修改成功");
                    } else if (mAsResult.getResultMsg() != null) {
                        ToastUtil.showToast(getContext(), mAsResult.getResultMsg());
                    }
                    break;

                default:
                    break;
            }

        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    /**
     * 修改用户资料
     *
     * @param value 修改的数据
     * @param type  修改的类型(姓名,年龄等)
     */
    @Override
    public void saveUserData(String value, String type) {
        if (isViewAttached()) {
            getMvpView().showLoading();
        }
        model.saveUserData(value, type);
    }
}
